package com.spring.cloud.provide.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.spring.cloud.provide.service.ProvideService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/provide")
public class ProvideController {
    public Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    ProvideService provideService;

    @RequestMapping("/ribbon")
    public String ribbon(@RequestParam String name){
        log.info("========ribbon=========");
        return provideService.ribbon(name);
    }


    @RequestMapping("/turbine")
    @HystrixCommand(fallbackMethod = "turbineError")
    public String turbine(@RequestParam String name){
        log.info("================= hi" +name+" from provide turbine");
        return "hi" +name+" from provide turbine";
    }

    public String turbineError(String name){
        log.info("================= hi" +name+" from provide turbine error");
        return "hi" +name+" from provide turbine error";
    }
}
